package com.skivingcloud.report.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.report.entity.ReportMain;
import com.skivingcloud.report.mapper.ReportMainMapper;
import com.skivingcloud.report.service.ReportMainService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * 报表管理 服务层实现。
 *
 * @author skivingcloud
 * @since 2024-09-12
 */
@Service
public class ReportMainServiceImpl extends ServiceImpl<ReportMainMapper, ReportMain> implements ReportMainService {

    /**
     * 分页查询报表管理
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<ReportMain> queryByPage(PageParameter<ReportMain> parameter){
        Page<ReportMain> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(ReportMain::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportName())) {
                queryWrapper.and(ReportMain::getReportName).like(parameter.getParam().getReportName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportCode())) {
                queryWrapper.and(ReportMain::getReportCode).like(parameter.getParam().getReportCode());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportGroup())) {
                queryWrapper.and(ReportMain::getReportGroup).like(parameter.getParam().getReportGroup());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportType())) {
                queryWrapper.and(ReportMain::getReportType).like(parameter.getParam().getReportType());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportImage())) {
                queryWrapper.and(ReportMain::getReportImage).like(parameter.getParam().getReportImage());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportDesc())) {
                queryWrapper.and(ReportMain::getReportDesc).like(parameter.getParam().getReportDesc());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportAuthor())) {
                queryWrapper.and(ReportMain::getReportAuthor).like(parameter.getParam().getReportAuthor());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getEnableFlag())) {
                queryWrapper.and(ReportMain::getEnableFlag).like(parameter.getParam().getEnableFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDeleteFlag())) {
                queryWrapper.and(ReportMain::getDeleteFlag).like(parameter.getParam().getDeleteFlag());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCreateBy())) {
                queryWrapper.and(ReportMain::getCreateBy).like(parameter.getParam().getCreateBy());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getUpdateBy())) {
                queryWrapper.and(ReportMain::getUpdateBy).like(parameter.getParam().getUpdateBy());
            }
        }
        return this.page(page, queryWrapper);
    }
}
